var ph = $("#phomne");
var reg = /^1[34578]\d{9}/;
ph.blur(function() {
	ph.next().html(ph.val() == "" ? "<img align='center' src='ZCimg/onError.gif' />不能为空" : (reg.test(ph.val()) == false ? "<img align='center' src='ZCimg/onError.gif' />请输入正确的手机号！" : "<img align='center' src='ZCimg/onsuccess.gif' />"));
});
var pwd = $("#pwd");
var rew = /^[0-9]{4,9}[A-Za-z]+$/
pwd.blur(function() {
	pwd.next().html(pwd.val() == "" ? "<img align='center' src='ZCimg/onError.gif' />请输入6-12位数字或字母组成的密码！" : (rew.test(pwd.val()) == false ? "<img align='center' src='ZCimg/onError.gif' />密码格式不符合！" : "<img align='center' src='ZCimg/onsuccess.gif' />"));
});
var pwds = $("#pwds");
pwds.blur(function() {
	pwds.next().html(pwds.val() == "" ? "<img align='center' src='ZCimg/onError.gif' />确认密码不能为空！" : ((pwds.val() == pwd.val()) ? "<img align='center' src='ZCimg/onsuccess.gif' />" : "<img align='center' src='ZCimg/onError.gif' />密码格式不相同！"));
});
var nc = $("#nc");
var ret = /^[\u4e00-\u9fa5]+|[A-za-z]{6}$/;
nc.blur(function() {
	nc.next().html(nc.val() == "" ? "<img align='center' src='ZCimg/onError.gif' />昵称是必填项！" : (ret.test(nc.val()) == false ? "<img align='center' src='ZCimg/onError.gif' />昵称格式不符合！" : "<img align='center' src='ZCimg/onsuccess.gif' />"));
});

function check() {
	var pd = 0;
	if(reg.test(ph.val())) {
		pd++;
	}
	if(rew.test(pwd.val())) {
		pd++;
	}
	if(pwds.val() == pwd.val()) {
		pd++;
	}
	if(ret.test(nc.val())) {
		pd++;
	}
	if(pd == 4) {
		console.log("成功");
		regs()
	} else {
		console.log("错误");
	}
}

function regs() {
	$.ajax({
		type: "POST",
		url: "https://api.leancloud.cn/1.1/users",
		async: true,
		headers: {
			"X-LC-Id": "eG22PNfwqck3fDTem41ACiNU-gzGzoHsz",
			"X-LC-Key": "Y8VoXz0cIzsJVbpctUAJXAAh",
			"Content-Type": "application/json"
		},
		data: '{"username":"' + $("#nc").val() + '","phone":"' + $("#phomne").val() + '","password":"' + $("#pwd").val() + '"}',
		success: function(ret) {
			location.href = "denglu.html";
			console.log("发送success");
		},
		error: function(error) {
			console.log("发送error")
			console.log(JSON.parse(error.responseText));
		}
	});
}